package com.blast.comicsisland.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * author : hg
 * email: 530157892@qq.com
 * 15/6/8.
 */
public class CacheUtils {

    private CacheUtils(){}

    public static String md5(String url){
        String ret = null;

        if (url != null) {
            try {
                MessageDigest digest = MessageDigest.getInstance("MD5");

                byte[] data = digest.digest(url.getBytes());
                
                ret = toHex(data);

            } catch (NoSuchAlgorithmException e) {
                e.printStackTrace();
            }
        }



        return ret;
    }

    private static String toHex(byte[] data) {
        String ret = null;
        if (data != null) {

            StringBuilder builder = new StringBuilder();

            for (byte b : data) {

                int h,l;

                l = b&0x0f;

                h = (b>>4)&0x0f;

                builder.append(Integer.toString(h)).append(Integer.toString(l));
            }

            ret = builder.toString();
        }


        return ret;
    }



}
